package LeetCode.NumOffer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * @author lumin
 * @date 2022/05/16 17:56
 **/
public class NumOffer32_1 {
    public int[] levelOrder(TreeNode root) {
        if(root == null){
            return new int[0];
        }
        Queue<TreeNode> que = new LinkedList<TreeNode>(){{ add(root); }};
        ArrayList<Integer> ret = new ArrayList<Integer>();
        while(!que.isEmpty()){
            TreeNode node = que.poll();
            ret.add(node.val);
            if(root.left != null){
                que.add(node.left);
            }
            if(root.right != null){
                que.add(node.right);
            }
        }
        int[] arr = new int[ret.size()];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = ret.get(i);
        }
        return arr;
    }
}